
 import React, { Component } from 'react'
 import axios from 'axios'
 import url from '../config/url'
 import PropTypes from 'prop-types'
 
 class Captcha extends Component {
     state = {}
 
     render() {
         return (
             <img
                 src={this.state.img}
                 alt="验证码"
                 title="点击刷新验证码"
                 height={this.props.h}
                 width={this.props.w}
                 onClick={() => this.loadCap()}
             />
         )
     }
 
     componentDidMount() {
         this.loadCap()
     }
 
     loadCap() {
         axios.get(url.GetCaptcha).then((res) => {
             this.setState({
                 img: res.data.img,
             })
             // 保存key值
             this.props.setKey && this.props.setKey(res.data.key)
         })
     }
 
     // 坑：后续需要回来取消网络请求。
 }
 
 Captcha.defaultProps = {
     w: '70%',
     h: 36,
     
 }
 Captcha.propTypes = {
     setKey: PropTypes.func.isRequired
 }
 
 export default Captcha
 